/*
 * @Author       : 许警
 * @Date         : 2024-04-02 10:38:00
 * @LastEditors  : 许警
 * @LastEditTime : 2024-04-25 14:46:56
 * @FilePath     : /src/directive/permission/has.js
 * @Description  :
 */
import store from '../../store'
export function filterRoutes(routes, old) {
  const res = []
  routes.forEach(r => {
    let first = old.filter(a => a.title == r.name)
    const temp = { ...first[0] }
    // debugger
    if (r.children) {
      r.children = filterRoutes(r.children, first[0].children)
    }

    res.push(temp)
  })

  return res
}
/* 
检查权限自定义指令
v-permission
全局挂载、
*/
function checkPermission(el, binding) {
  const { value } = binding
  debugger
  console.log(value, 'vvvvvvvvvvv---------------------------------')
  if (value) {
    let routers = JSON.parse(localStorage.getItem('routers'))
    // routers.

    // if (value.length > 0) {
    //     const permissionRoles = value
    //     const hasPermission = roles.some(role => {
    //         return permissionRoles.includes(role)
    //     })
    //     if (!hasPermission) {
    //         // 没有权限删除当前节点
    //         el.parentNode && el.parentNode.removeChild(el)
    //     }
    // }
  } else {
    throw new Error(`need roles! Like v-permission="['admin','editor']"`)
  }
}
export default {
  inserted(el, binding) {
    checkPermission(el, binding)
  }
}
